
import java.util.HashMap;
import java.util.Map;

public class Solution1 {
    //3. 无重复字符的最长子串
    public int lengthOfLongestSubstring(String s) {
        int n = s.length();
        Map<Character,Integer> hash = new HashMap<>();
        int len = 0;
        for (int left = 0, right = 0; right < s.length(); right++) {
            char in = s.charAt(right);
            hash.put(in,hash.getOrDefault(in,0)+1);
            while (hash.get(in) > 1) {
                char out = s.charAt(left);
                hash.put(out,hash.get(out) - 1);
                left++;
            }
            len = Math.max(len,right-left+1);
        }
        return len;
    }
}

